Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

191
Visualizações
"if [ -z $variable ]" in a shell script is not recognising my variable

When I run the following script it keeps defaulting to the else statement and I'm not sure why. I have even included an echo $workflow which showed me the name that I was expecting to see but it still keeps defaulting to the else statement.

I've tried including an export namecheck=$workflow to see if that was the issue but it still gave the same end result

#!/bin/sh

read -p "Enter the workflow name: " workflowName

workflowName=${workflowName}

curl --request GET --url https://website.com > workflowjson.txt

workflow=$(jq -r .metadata.name workflowjson.txt)

echo $workflow

if [ -z "$workflow" ] then
    echo "Workflow is Valid" 
else
    echo "Workflow is not valid" 
fi
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

man test shows

-z STRING the length of STRING is zero

The code outputs Workflow is Valid when the workflow is empty.

Switch the then and else parts, or negate the condition (use -n instead of -z).

over 4 years ago · Santiago Trujillo Relatório

0

try taking the quotes out around workflow and put then in a separate line

if [ -z $workflow ]
then
  echo "Workflow is Valid" 
else
  echo "Workflow is not valid"
fi
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda